package com.manager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easyCode.feature.mybaits.CustomPage;
import com.easyCode.feature.result.ResponseResultAdvice;
import com.manager.convert.StrToListFormatter;
import com.manager.entity.dao.UserFreeListener;
import com.manager.entity.dto.UserFreeListenerDto;
import com.manager.entity.vo.UserFreeListenerVo;
import com.manager.service.IUserFreeListenerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.DataBinder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RestController
@RequestMapping("/userFreeListener")
@RequiredArgsConstructor
@ResponseResultAdvice
@Api(tags = "用户免费试听请求")
public class UserFreeListenerController {
    private final IUserFreeListenerService iUserFreeListenerService;

    @InitBinder
    public void initBinder(DataBinder dataBinder){
        dataBinder.addCustomFormatter(new StrToListFormatter());
    }

    @ApiOperation("根据号码查询免费试听用户")
    @GetMapping("/{phoneNumber}")
    public UserFreeListenerDto getUserFreeListener(@PathVariable("phoneNumber") Integer phoneNumber) {
        return iUserFreeListenerService.getUserFreeListenerByPhoneNumber(phoneNumber);
    }

    @ApiOperation("分页批量查询免费试听用户")
    @GetMapping("/list")
    public List<UserFreeListenerDto> listUserFreeListener(CustomPage customPage) {
        return iUserFreeListenerService.listUserFreeListener(customPage);
    }

    @ApiOperation("批量删除免费试听用户")
    @DeleteMapping("/batch")
    public void delUserFreeListener(@RequestParam("userIds")List<Integer> userIds) {
        iUserFreeListenerService.removeBatchByIds(userIds);
    }
}
